#include <stdio.h>

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* detectCycle(struct ListNode* head) {
    struct ListNode* slow = head;
    struct ListNode* fast = head;

    int answer = 0;

    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if (slow == fast)
        {
            answer = 1;
            break;
        }
    }

    if (answer == 0)
        return NULL;
    else
    {
        struct ListNode* cur = head;
        while (slow != cur)
        {
            cur = cur->next;
            slow = slow->next;
        }
        return cur;
    }
}

int main()
{
	return 0;
}